package net.tngou.tpage.quartz;

import static org.quartz.CronScheduleBuilder.cronSchedule;
import static org.quartz.JobBuilder.newJob;
import static org.quartz.SimpleScheduleBuilder.simpleSchedule;
import static org.quartz.TriggerBuilder.newTrigger;

import java.io.File;
import java.util.Date;

import javax.servlet.ServletContextEvent;

import org.apache.commons.configuration2.PropertiesConfiguration;
import org.apache.commons.configuration2.builder.FileBasedConfigurationBuilder;
import org.apache.commons.configuration2.builder.fluent.Configurations;
import org.apache.commons.configuration2.builder.fluent.Parameters;
import org.apache.commons.configuration2.ex.ConfigurationException;
import org.apache.commons.lang3.time.DateUtils;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleTrigger;
import org.quartz.Trigger;
import org.quartz.impl.StdSchedulerFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.tngou.tpage.util.ConfigUtil;




public class JobManager
{
	private static Logger _log = LoggerFactory.getLogger(JobManager.class);
	private static Scheduler sched ;
	private static PropertiesConfiguration properties;
	static
	{	
		properties = ConfigUtil.GetConfig("quartz.properties");
		
	}
	
	
	public static void run() throws SchedulerException  
	{
		
		
		//创建一个简单的应用并且运行这个应用
		/**
		 * 一旦通过StdSchedulerFactory.getDefaultScheduler()获得一个scheduler ，那么应用将不会结束，
		 * 除非调用scheduler.shutdown()方法。
		 */
		sched = new StdSchedulerFactory().getScheduler();
		  _log.info("*********************启动应用*********************");
	
		
       sched.start();
       
        /**
         * 关闭应用
         */
      //  sched.shutdown();
	}
	
	
	public static void shutdown() throws SchedulerException 
	{
		if(sched!=null) 
		{
			sched.shutdown();
			 _log.info("*********************关闭应用*********************");
		}
	}
	


	
	
	
	public static void main(String[] args) throws SchedulerException {

		new JobManager().run();
		
		
	}
}
